import { RouteRecordRaw, createRouter, createWebHistory } from "vue-router";
import PageLayout from "../layout/PageLayout.vue";
import authority from "./modules/authority";
import files from "./modules/files";
import logs from "./modules/logs";
import monitor from "./modules/monitor";
import smartRecognition from "./modules/smartRecognition";
import task from "./modules/task";

export const constRoutes: RouteRecordRaw[] = [
  {
    path: "/",
    name: "home",
    component: PageLayout,
    redirect: { name: "device-statistic" },
    meta: {
      title: "首页",
      root: true,
    },
    children: [
      {
        path: "statistic",
        name: "device-statistic",
        component: () => import("@/views/home/DeviceStatistic"),
        meta: {
          title: "设备统计",
        },
      },
    ],
  },
  {
    path: "/login",
    name: "login",
    component: () => import("../views/LoginPage.vue"),
    meta: {
      title: "登录",
      hidden: true,
    },
  },
];

export const asyncRoutes = [
  authority,
  files,
  logs,
  monitor,
  task,
  smartRecognition,
];

const router = createRouter({
  history: createWebHistory(),
  routes: constRoutes,
});

export function resetRouter() {
  asyncRoutes.forEach((route) => {
    router.removeRoute(route.name);
  });
}

export default router;
